<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    手机号<input type="text" class="user"> <br>
    密码<input type="text" class="pwd"> <br>
    <button>登录</button>

    <script>

        const oUser = document.querySelector('.user');
        const oPwd = document.querySelector('.pwd');
        const oBtn = document.querySelector('button');


        oBtn.onclick = function () {
            const phone = oUser.value;
            const pwd = oPwd.value;

            // 判断手机号是否存在
            const res = localStorage.getItem(phone);
            console.log(res);   // json
            if (res) {
                // 判断密码
                const user = JSON.parse(res);   // 转回对象
                console.log(user);
                // 解构
                const { password } = user;
                if (password === pwd) {
                    // 记录是谁在登录
                    localStorage.setItem('LOGIN_USER', phone);
                    alert("ok");
                } else {
                    alert('err');
                }
            } else {
                alert('未注册');
            }
        }

    </script>

</body>

</html>